package com.tencreat.common.core.domain;

import com.tencreat.common.config.MinioConfig;
import com.tencreat.common.config.OssClient;
import lombok.extern.slf4j.Slf4j;

/**
 * 文件上传Factory
 *
 * @author zixin
 */
@Slf4j
public class OssFactory {

    private static OssClient OSS_CLIENT = null;

    /**
     * 获取默认实例
     */
    public static OssClient instance() {
        // 获取redis 默认类型
        if (OSS_CLIENT == null) {
            MinioConfig minioConfig = MinioConfig.getMinioConfig();
            OssProperties ossProperties = new OssProperties();
            ossProperties.setEndpoint(minioConfig.getEndpoint());
            ossProperties.setDomain(minioConfig.getAccessUrl());
            // ossProperties.setRegion("");
            ossProperties.setAccessKey(minioConfig.getAccessKey());
            ossProperties.setSecretKey(minioConfig.getSecretKey());
            ossProperties.setBucketName(minioConfig.getBucketName());
            ossProperties.setIsHttps("N");
            ossProperties.setAccessPolicy(AccessPolicyType.PUBLIC.getType());
            OSS_CLIENT = new OssClient(ossProperties);
        }
        return OSS_CLIENT;
    }

}
